package com.application.chiettinhdienluc.rsclient;


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.application.chiettinhdienluc.model.ChietTinhModel;



import android.util.Log;
 
public class RsPostClient {
	
	
	private static final String SERVICE_NAMESPACE = "http://tempuri.org/";
	private static final String SERVICE_SOAP_ACTION = "http://tempuri.org/";
	
    private String URI;
   
    public RsPostClient(String uri)
    {
    	URI = uri;    	
    }
 
    public String submitHoSoChietTinh(ChietTinhModel ct, String webMethName) {
        String resTxt = null;
      
        SoapObject request = new SoapObject(SERVICE_NAMESPACE, webMethName);
    
   
        request.addProperty(createProperty("maYcauKnai",ct.get_MaYeuCauKhieuNai(),String.class ));   
        request.addProperty(createProperty("tenKhang",ct.get_TenKhachHang(),String.class ));
        
        request.addProperty(createProperty("lan", "1" , Long.class ));
        request.addProperty(createProperty("maDviqly", "PB1701",String.class ));
        request.addProperty(createProperty("maloaiHs", "GM",String.class ));
        
        
        
        //httpPost.setHeader("Content-Type",  "application/json; charset=utf-8");
        //httpPost.setHeader("Accept", "application/json");
                
        
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);       
        envelope.dotNet = false;      
        
        Log.i("Request content", request.toString());
        
        envelope.setOutputSoapObject(request);
        
	   
       
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URI);
        
 
        try {
            // Invoke web service
            androidHttpTransport.call(SERVICE_SOAP_ACTION+webMethName, envelope);
            // Get the response
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            // Assign it to resTxt variable static variable
            resTxt = response.toString();
 
        } catch (Exception e) {            
            e.printStackTrace();           
            resTxt = "Error occured. " + e.toString();
        } 
       
        return resTxt;
    }        
    
    private PropertyInfo createProperty(String name, String value, Object type) {
    	
    	 PropertyInfo p = new PropertyInfo();        
         p.setName(name);       
         p.setValue(value);  
         p.setType(type);      
         
         
         return p;      
         
    }
        
}